/**
* 
* Sonde system specific system sonde 
* Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN  
* 
* see <a href="{@docRoot}/Documentation/sonde.html"> for more information</a>
* 
* @author: Urunuela Richard
* @version 3.2
*/
package report;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;

import java.lang.reflect.*;

import log.powerTrace;


import programme.GUI.JConsole;
import storm.ISimulationKernel;
import storm.SimulationKernel;
import storm.Processors.Processor;
import storm.Schedulers.Scheduler;

public class system extends sonde {

	ISimulationKernel  kernel;
/**
 * 
 * @param oo
 * @param iSimulationKernel
 */

	public system(output oo,ISimulationKernel  iSimulationKernel) {
		super(oo);
		this.kernel = iSimulationKernel;
		this.theOutPut.appendSection("System");
	}
/**
 * 
 */
	public boolean parse(String s){
		return super.parse(s);
	}
	/**
	 * superclass field 
	 */
	public void internalData(String commande) {
		if (commande.compareToIgnoreCase("duration")==0){
			this.theOutPut.addligne("Duration " + this.kernel.getDuration()+"");
			
			
		}
		if (commande.compareToIgnoreCase("sumpower")==0){
			this.theOutPut.addligne("Power Consumption");
			ArrayList cpus = this.kernel.getTasksListeManager().getALLProcessors();
			Iterator i = cpus.iterator();
			double resAll=0;
			while(i.hasNext()){
				double res = 0;
				Processor P = (Processor) i.next();
				int id = P.getId();
				ArrayList cpuPC = this.kernel.getLogs().getHistoPowerbyId(id);
				/**
				 * check if cpu is use if not this list is empty
				 */
				if (cpuPC != null ) {
					for (int k=0;k <  cpuPC.size();k++){
							powerTrace T = (powerTrace) cpuPC.get(k);
							res = res + T.power;		
					}
				}
				  res = res  *this.kernel.getprecision() / 1000; //unité de mésure en ms
				  resAll = resAll+res;
				//parcours stat;
				this.theOutPut.addligne("Processor " + P.getId() + " Power (J) " + res); 
			}
			this.theOutPut.addligne("Sum (J) " + resAll); 
		}

	}

	
}
